package com.bcbim.api_web.health.controller;

import com.alibaba.fastjson.JSONObject;
import com.bcbim.api_web.sys.init.code.CodeMap;
import com.bcbim.authentication_interface.util.AuthUtil;
import com.bcbim.common.response.annotation.Translate;
import com.bcbim.common.response.vo.ReturnMsg;
import com.bcbim.common.response.vo.ReturnPageMsg;
import com.bcbim.common.sys.Code;
import com.bcbim.common.sys.Constant;
import com.bcbim.common.sys.ParamException;
import com.bcbim.common.util.GuidUtil;
import com.bcbim.common.util.LngLonUtil;
import com.bcbim.common.util.ParamCheck;
import com.bcbim.smart_water_interface.health.bo.HealthBO;
import com.bcbim.smart_water_interface.health.bo.RenewHealthBO;
import com.bcbim.smart_water_interface.health.bo.UpdateFlawLatLonBO;
import com.bcbim.smart_water_interface.health.dao.FlawDO;
import com.bcbim.smart_water_interface.health.dao.HealthDAO;
import com.bcbim.smart_water_interface.health.dto.ListHealthManagementDTO;
import com.bcbim.smart_water_interface.health.dto.UploadHealthImgDTO;
import com.bcbim.smart_water_interface.health.dto.UploadHealthVideoDTO;
import com.bcbim.smart_water_interface.health.service.HealthService;
import com.bcbim.smart_water_interface.health.vo.*;
import com.bcbim.smart_water_interface.line.service.PipelineLineService;
import com.bcbim.smart_water_interface.point.service.PipelinePointService;
import com.google.common.collect.Lists;
import com.sun.scenario.effect.ImageData;
import net.sf.jxls.transformer.RowCollection;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 健康检测管理
 * @Author: ye
 * @Date: 2021/10/29
 * @Version: V1.0
 **/
@RestController
@RequestMapping("/healthManagement")
public class HealthManagementController {

    @Value("${application.upload-path}")
    private String UPLOAD_PATH;
    @Value("${application.upload-video-path}")
    private String UPLOAD_VIDEO_PATH;

    @Reference(protocol = "dubbo", group = "health", version = "1.0.0")
    private HealthService healthServiceImpl;
    @Reference(protocol = "dubbo", group = "pipelineLine", version = "1.0.0")
    private PipelineLineService lineService;
    @Reference(protocol = "dubbo", group = "pipelinePoint", version = "1.0.0")
    private PipelinePointService pointService;

    /**
     * @Description: 健康检测列表
     * @Param: ListHealthManagementDTO
     * @Return: ReturnPageMsg
     * @Author: ye
     * @Date: 2021/10/29
     */
    @Translate
    @PostMapping("listHealth")
    public ReturnPageMsg listHealth(ListHealthManagementDTO query) {
        try {
            ParamCheck.pageNumCheck(query.getPageNum(), query.getPageSize());
        } catch (ParamException e) {
            return ReturnPageMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        List<HealthManagementVO> list = new ArrayList<>();
        int total = healthServiceImpl.countHealthManagement(query);
        if (total > 0) {
            query.setStart((query.getPageNum() - 1) * query.getPageSize());
            list = healthServiceImpl.listHealthManagement(query);
        }
        return ReturnPageMsg.consSuccess(total, list);
    }

    /**
     * @Description: 查询详情
     * @Param: healthId
     * @Return: ReturnMsg
     * @Author: ye
     * @Date: 2021/11/1
     */
    @Translate
    @PostMapping("getHealthInfo")
    public ReturnMsg getHealthInfo(String healthId) {
        try {
            ParamCheck.idCheck(healthId);
        } catch (ParamException e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        HealthManagementInfoVO healthInfoVo = healthServiceImpl.getHealthManagementInfo(healthId);
        if (ObjectUtils.isEmpty(healthInfoVo)) {
            return ReturnMsg.consSuccess();
        }
        healthInfoVo.setArrFlaw(healthServiceImpl.getFlawManagementInfo(healthId));
        if (healthInfoVo.getDiameter().contains("*")) {
            healthInfoVo.setLineType("0");
        } else {
            healthInfoVo.setLineType("1");
        }
        return ReturnMsg.consSuccess(healthInfoVo);
    }

    /**
     * @Description: 上传图片
     * @Param:
     * @Return:
     * @Author: ye
     * @Date: 2021/11/1
     */
    @PostMapping("uploadHealthImg")
    public ReturnMsg uploadHealthImg(@RequestParam MultipartFile file) {
        try {
            ParamCheck.objectNotEmpty(file);
        } catch (ParamException e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        String filename = file.getOriginalFilename();
        if (filename.length() > 100) {
            return ReturnMsg.consFail("文件名最长为100");
        }
        String suffix = filename.substring(filename.lastIndexOf("."));
        String newName = GuidUtil.get() + suffix;

        String path = UPLOAD_PATH + Constant.HEALTH_IMG_URL + File.separator;
        File dest = new File(new File(path).getAbsolutePath() + File.separator + newName);
        if (!dest.getParentFile().exists()) {
            dest.getParentFile().mkdirs();
        }
        try {
            //保存文件
            file.transferTo(dest);
        } catch (Exception e) {
            return ReturnMsg.consFail("文件上传失败");
        }
        JSONObject result = new JSONObject();
        result.put("url", "/picture/" + Constant.HEALTH_IMG_URL + "/" + newName);
        return ReturnMsg.consSuccess(result);
    }

    /**
     * @Description: 编辑健康检测
     * @Param:
     * @Return:
     * @Author: ye
     * @Date: 2021/11/1
     */
    @PostMapping("updateHealthInfo")
    public ReturnMsg updateHealthInfo(@RequestBody HealthManagementInfoVO info) {
        try {
            ParamCheck.idCheck(info.getHealthId());
            ParamCheck.idCheck(info.getLineId());
            ParamCheck.stringCanBeEmpty(info.getMonitoringPersonnel(), 20);
            ParamCheck.stringCanBeEmpty(info.getMonitoringSite(), 20);
            ParamCheck.stringCanBeEmpty(info.getMonitoringSite(), 20);
            if (ObjectUtils.isNotEmpty(info.getArrFlaw()) && info.getArrFlaw().size() > 0) {
                for (FlawManagementInfoVO flaw : info.getArrFlaw()) {
                    ParamCheck.idCheck(flaw.getDefectId());
                    if (flaw.getPhotoName().length() > 100) {
                        flaw.setPhotoName(flaw.getPhotoName().substring(0, 100));
                    }
                }
            }
        } catch (ParamException e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }

        healthServiceImpl.updateHealthInfo(info);
        healthServiceImpl.clearHealthFlaw(info.getHealthId());
        if (ObjectUtils.isNotEmpty(info.getArrFlaw()) && info.getArrFlaw().size() > 0) {
            List<FlawDO> flawDOS = new ArrayList<>();
            UpdateFlawLatLonBO flawLatLonBO = healthServiceImpl.getHealthLineLatLon(info.getHealthId());
            for (FlawManagementInfoVO flawInfo : info.getArrFlaw()) {
                FlawDO flawDO = new FlawDO();
                flawDO.setId(GuidUtil.get());
                flawDO.setHealthId(info.getHealthId());
                flawDO.setLocation(flawInfo.getLocation());
                if (flawLatLonBO != null && ObjectUtils.isNotEmpty(flawInfo.getLocation())) {
                    double angle = LngLonUtil.getAngle(flawLatLonBO.getStartLat(),flawLatLonBO.getStartLon(),flawLatLonBO.getEndLat(),flawLatLonBO.getEndLon());
                    double[] latlon = LngLonUtil.computerThatLonLat(flawLatLonBO.getStartLat(), flawLatLonBO.getStartLon(), angle, flawInfo.getLocation());
                    flawDO.setLatitude(latlon[0]);
                    flawDO.setLongitude(latlon[1]);
                }
                flawDO.setDefectId(flawInfo.getDefectId());
                flawDO.setDefectLevelId(flawInfo.getLevelId());
                flawDO.setPipelineSituation(flawInfo.getPipelineSituation());
                flawDO.setPhotoName(flawInfo.getPhotoName());
                flawDO.setPhotoUrl(flawInfo.getPhotoUrl());
                flawDO.setCreateBy(AuthUtil.getUserIdDecrypt());
                flawDO.setCreateTime(LocalDateTime.now());
                flawDO.setDel(Constant.NOT_DEL);
                flawDOS.add(flawDO);
            }
            healthServiceImpl.insertFlawInfo(flawDOS);
        }
        return ReturnMsg.consSuccess("保存成功");
    }

    /**
     * @Description: 上传管壁全景图
     * @Param: UploadHealthImgDTO
     * @Return: ReturnMsg
     * @Author: ye
     * @Date: 2021/11/1
     */
    @PostMapping("uploadLineWallImg")
    public ReturnMsg uploadLineWallImg(UploadHealthImgDTO query) {
        try {
            ParamCheck.stringCanBeEmpty(query.getUrl(), 100);
            ParamCheck.idCheck(query.getHealthId());
        } catch (Exception e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        HealthDAO healthDAO = new HealthDAO();
        healthDAO.setId(query.getHealthId());
        healthDAO.setLineWallImg(query.getUrl());
        healthServiceImpl.uploadLineWallImg(query);
        return ReturnMsg.consSuccess("保存成功");
    }

    /**
     * @Description: 上传模型截面图
     * @Param: UploadHealthImgDTO
     * @Return: ReturnMsg
     * @Author: ye
     * @Date: 2021/11/1
     */
    @PostMapping("uploadLineSectionImg")
    public ReturnMsg uploadLineSectionImg(UploadHealthImgDTO query) {
        try {
            ParamCheck.stringCanBeEmpty(query.getUrl(), 100);
            ParamCheck.idCheck(query.getHealthId());
        } catch (Exception e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        HealthDAO healthDAO = new HealthDAO();
        healthDAO.setId(query.getHealthId());
        healthDAO.setLineSectionImg(query.getUrl());
        healthServiceImpl.uploadLineSectionImg(query);
        return ReturnMsg.consSuccess("保存成功");
    }

    /**
     * @Description: 删除健康检测
     * @Param: healthId
     * @Return: ReturnMsg
     * @Author: ye
     *
     * @Date: 2021/11/1
     */
    @PostMapping("removeHealth")
    public ReturnMsg removeHealth(String healthId) {
        try {
            ParamCheck.idCheck(healthId);
        } catch (ParamException e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        healthServiceImpl.removeHealth(healthId);
        return ReturnMsg.consSuccess("删除成功");
    }

    /**
     * @Description: 上传健康监测视频
     * @Param: file
     * @Return: ReturnMsg
     * @Author: ye
     * @Date: 2021/11/18
     */
    @PostMapping("uploadHealthVideo")
    public ReturnMsg uploadHealthVideo(@RequestParam MultipartFile file) {
        try {
            ParamCheck.objectNotEmpty(file);
        } catch (ParamException e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        String filename = file.getOriginalFilename();
        if (filename.length() > 100) {
            return ReturnMsg.consFail("文件名最长为100");
        }
        String suffix = filename.substring(filename.lastIndexOf("."));
        if (!".mp4".equals(suffix)) {
            return ReturnMsg.consFail("请上传mp4视频");
        }

        String newName = System.currentTimeMillis() + filename;
        String path = UPLOAD_VIDEO_PATH;
        File dest = new File(new File(path).getAbsolutePath() + File.separator + newName);
        if (!dest.getParentFile().exists()) {
            dest.getParentFile().mkdirs();
        }
        try {
            //保存文件
            file.transferTo(dest);
        } catch (Exception e) {
            return ReturnMsg.consFail("文件上传失败");
        }
        JSONObject result = new JSONObject();
        result.put("url", newName);
        return ReturnMsg.consSuccess(result);
    }

    /**
     * @Description: 查询缺陷代码
     * @Param:
     * @Return: ReturnMsg
     * @Author: ye
     * @Date: 2021/11/4
     */
    @PostMapping("selectDefect")
    public ReturnMsg selectDefect() {
        List<SelectDefectVO> list = healthServiceImpl.selectDefect();
        return ReturnMsg.consSuccess(list);
    }

    /**
     * @Description: 缺陷等级下拉
     * @Param: defectId
     * @Return: ReturnMsg
     * @Author: ye
     * @Date: 2021/11/4
     */
    @PostMapping("selectDefectLevel")
    public ReturnMsg selectDefectLevel(String defectId) {
        try {
            ParamCheck.idCheck(defectId);
        } catch (ParamException e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        List<SelectDefectLevelVO> list = healthServiceImpl.selectDefectLevel(defectId);
        return ReturnMsg.consSuccess(list);
    }

    /**
     * @Description: 保存健康监测视频
     * @Param:
     * @Return:
     * @Author: ye
     * @Date: 2021/11/13
     */
    @PostMapping("saveHealthVideo")
    public ReturnMsg saveHealthVideo(UploadHealthVideoDTO videoDTO) {
        try {
            ParamCheck.idCheck(videoDTO.getHealthId());
            ParamCheck.stringCanBeEmpty(videoDTO.getVideoName(), 200);
            ParamCheck.stringCanBeEmpty(videoDTO.getVideoUrl(), 200);
        } catch (ParamException e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        healthServiceImpl.saveHealthVideo(videoDTO);
        return ReturnMsg.consSuccess("保存成功");
    }

    /**
     * @Description: 上传健康监测文件
     * @Param: file
     * @Return: ReturnMsg
     * @Author: ye
     * @Date: 2021/11/1
     */
    @PostMapping("uploadHealthDoc")
    public ReturnMsg uploadHealthDoc(@RequestParam MultipartFile file) {
        try {
            ParamCheck.objectNotEmpty(file);
        } catch (ParamException e) {
            return ReturnMsg.consFail(ParamException.PARAMETER_ERROR);
        }
        String filename = file.getOriginalFilename();
        String suffix = filename.substring(filename.lastIndexOf("."));
        if (!".doc".equals(suffix) && !".docx".equals(suffix)) {
            return ReturnMsg.consFail("请上传doc文档");
        }

        String newName = System.currentTimeMillis() + filename;
        String path = UPLOAD_PATH + Constant.HEALTH_DOC_URL + File.separator;
        File dest = new File(new File(path).getAbsolutePath() + File.separator + newName);
        if (!dest.getParentFile().exists()) {
            dest.getParentFile().mkdirs();
        }
        try {
            //保存文件
            file.transferTo(dest);
        } catch (Exception e) {
            return ReturnMsg.consFail("文件上传失败");
        }
        JSONObject result = new JSONObject();
        result.put("url", Constant.HEALTH_DOC_URL + "/" + newName);
        return ReturnMsg.consSuccess(result);
    }

    /**
     * @Description: 更新健康监测信息
     * @Param: url 文件路径
     * @Return: ReturnMsg
     * @Author: ye
     * @Date: 2021/11/9
     */
//    @PostMapping("renewHealth")
//    public ReturnMsg renewHealth(String url) throws Exception {
//        if (StringUtils.isEmpty(url)) {
//            return ReturnMsg.consFail("文件错误");
//        }
//        if (!url.contains(Constant.HEALTH_DOC_URL)) {
//            return ReturnMsg.consFail("文件错误");
//        }
//        String suffix = url.substring(url.lastIndexOf("."));
//        if (!".docx".equals(suffix) && !".doc".equals(suffix)) {
//            return ReturnMsg.consFail("文件格式错误");
//        }
//        Document doc = null;
//        try {
//            doc = new Document(UPLOAD_PATH + url);
//        } catch (Exception e) {
//            return ReturnMsg.consFail("文件读取失败");
//        }
//        //解析word数据表格 获取 健康检测数据 和 缺陷数据
//        //根据缺陷数据, 对word数据文档中的图片进行名称及落地
//        RenewHealthBO bo = getData(doc);
//
//        getPhoto(doc, bo.getPhotoNameList());
//        return ReturnMsg.consSuccess("已成功导入" + bo.getCount() + "条数据");
//    }
//
//
//    private RenewHealthBO getData(Document doc) {
//        //获取word中所有表格
//        NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);
//
//        //照片对应映射存储对象
//        List<String> photoNameList = Lists.newArrayList();
//
//        //计数器
//        int count = 0;
//
//        //遍历表格
//        for (Table table : (Iterable<Table>) tables) {
//            RowCollection rows = table.getRows();
//            List<String> checkTableValue = getRowValue(rows.get(0));
//            //不是健康检测表格跳过
//            if (!"录像文件".equals(checkTableValue.get(0))) {
//                continue;
//            }
//
//            HealthBO health = new HealthBO();
//            List<FlawDO> flaws = new ArrayList<>();
//            String healthId = GuidUtil.get();
//            health.setId(healthId);
//
//            //遍历行
//            for (Row row : table.getRows()) {
//
//                //获取行单元格值 list
//                List<String> rowValList = getRowValue(row);
//
//                //组装健康检测对象 Health
//                assemblyHealth(rowValList, health);
//
//                if ((isNumber(rowValList.get(0).replace("m", "")) || StringUtils.isEmpty(rowValList.get(0))) && rowValList.size() >= 6) {
//                    //组装缺陷对象 Flaw
//                    FlawDO flaw = assemblyFlaw(rowValList, healthId);
//                    //照片对应映射
//                    String photoName = healthId + "-" + flaw.getPhotoName();
//                    photoNameList.add(photoName);
//                    flaw.setPhotoUrl("/picture/" + Constant.HEALTH_IMG_URL + "/" + photoName + ".jpg");
//                    flaws.add(flaw);
//                }
//            }
//
//            if (StringUtils.isEmpty(health.getStartPoint()) || StringUtils.isEmpty(health.getEndPoint())) {
//                continue;
//            }
//
//            String startPointId = pointService.getPointIdByCode(health.getStartPoint());
//            if (StringUtils.isEmpty(startPointId)) {
//                startPointId = GuidUtil.get();
//                PipelinePointDO startPoint = new PipelinePointDO();
//                startPoint.setId(startPointId);
//                startPoint.setCode(health.getStartPoint());
//                if (ObjectUtils.isNotEmpty(health.getStartBury())) {
//                    startPoint.setBury(health.getStartBury().toString());
//                }
//                startPoint.setCreateTime(LocalDateTime.now());
//                startPoint.setCreateBy(AuthUtil.getUserIdDecrypt());
//                startPoint.setDel(Constant.NOT_DEL);
//                startPoint.setPolicyType("0");
//                pointService.insertPipelinePointData(startPoint);
//            }
//            String endPointId = pointService.getPointIdByCode(health.getEndPoint());
//            if (StringUtils.isEmpty(endPointId)) {
//                endPointId = GuidUtil.get();
//                PipelinePointDO endPoint = new PipelinePointDO();
//                endPoint.setId(endPointId);
//                endPoint.setCode(health.getEndPoint());
//                if (ObjectUtils.isNotEmpty(health.getEndBury())) {
//                    endPoint.setBury(health.getEndBury().toString());
//                }
//                endPoint.setCreateTime(LocalDateTime.now());
//                endPoint.setCreateBy(AuthUtil.getUserIdDecrypt());
//                endPoint.setDel(Constant.NOT_DEL);
//                endPoint.setPolicyType("0");
//                pointService.insertPipelinePointData(endPoint);
//            }
//            String lineId = lineService.getLineIdByPoints(health.getStartPoint(), health.getEndPoint());
//            if (StringUtils.isEmpty(lineId)) {
//                lineId = GuidUtil.get();
//                PipelineLineDO line = new PipelineLineDO();
//                line.setId(lineId);
//                line.setStartPointId(startPointId);
//                line.setEndPointId(endPointId);
//                line.setCode(health.getStartPoint() + "-" + health.getEndPoint());
//                line.setPolicyType("0");
//                if (health.getUses().contains("污")) {
//                    line.setUses("2");
//                } else if (health.getUses().contains("雨")) {
//                    line.setUses("3");
//                } else {
//                    line.setUses("1");
//                }
//                String lineMaterial = lineService.getLineMaterial(health.getMaterial());
//                if (StringUtils.isEmpty(lineMaterial)) {
//                    Integer maxMaterialCode = lineService.getMaxMaterialCode();
//                    lineMaterial = String.valueOf(maxMaterialCode + 1);
//                    Code code = new Code();
//                    code.setCode(lineMaterial);
//                    code.setValue(health.getMaterial());
//                    CodeMap.MATERIAL_MAP.put(lineMaterial, health.getMaterial());
//                    lineService.insertMaterial(code);
//                }
//                line.setMaterial(lineMaterial);
//                line.setPipeDiameter(health.getPipeDiameter());
//                line.setDiameter(health.getDiameter());
//                line.setCreateBy(AuthUtil.getUserIdDecrypt());
//                line.setCreateTime(LocalDateTime.now());
//                line.setDel(Constant.NOT_DEL);
//                lineService.insertPipelineLineData(line);
//            }
//            health.setLineId(lineId);
//
//            if (flaws.size() == 1 && "74ca5fc705aa4d8099dcfb5f1d1a071a".equals(flaws.get(0).getDefectId())) {
//                health.setHealthStateType("1");
//            } else {
//                health.setHealthStateType("2");
//            }
//            health.setCreateBy(AuthUtil.getUserIdDecrypt());
//            health.setCreateTime(LocalDateTime.now());
//            health.setDel(Constant.NOT_DEL);
//
//            UpdateFlawLatLonBO latLonBO = lineService.getLineLatLon(lineId);
//
//            if (latLonBO != null &&
//                    ObjectUtils.isNotEmpty(latLonBO.getStartLon()) &&
//                    ObjectUtils.isNotEmpty(latLonBO.getStartLat()) &&
//                    ObjectUtils.isNotEmpty(latLonBO.getEndLon()) &&
//                    ObjectUtils.isNotEmpty(latLonBO.getEndLat())) {
//                for (FlawDO flawDO : flaws) {
//                    double angle = LngLonUtil.getAngle(latLonBO.getStartLat(), latLonBO.getStartLon(), latLonBO.getEndLat(), latLonBO.getEndLon());
//                    double[] latlon = LngLonUtil.computerThatLonLat(latLonBO.getStartLat(), latLonBO.getStartLon(), angle, flawDO.getLocation());
//                    flawDO.setLatitude(latlon[0]);
//                    flawDO.setLongitude(latlon[1]);
//                }
//            }
//
//            healthServiceImpl.removeLineHealth(lineId);
//            healthServiceImpl.insertHealth(health);
//            if (flaws.size() > 0) {
//                healthServiceImpl.insertFlawInfo(flaws);
//            }
//            System.out.println("count = " + count++);
//        }
//        RenewHealthBO bo = new RenewHealthBO();
//        bo.setCount(count);
//        bo.setPhotoNameList(photoNameList);
//        return bo;
//    }
//
//
//    /**
//     * 将行数据转换为list
//     * @param row word表格中行对象 Row
//     * @return 行数据list List<String>
//     */
//    private List<String> getRowValue(Row row) {
//        //获取行内单元格
//        Iterable<Cell> cells = row.getCells();
//        //返回集合
//        List<String> list = Lists.newArrayList();
//        for (Cell cell : cells) {
//            NodeCollection childNodes = cell.getChildNodes();
//            try {
//                list.add(StringUtils.deleteWhitespace(cell.toString(SaveFormat.TEXT)));
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//        return list;
//    }
//
//    private void getPhoto(Document doc, List<String> photoNameList) {
//        //获取图片
//        NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
//        //计数器
//        int i = 0;
//        for (Shape shape : (Iterable<Shape>) shapes) {
//            if (i == photoNameList.size()) {
//                break;
//            }
//            if (shape.hasImage()) {
//                ImageData data = shape.getImageData();
//                String photoName = photoNameList.get(i);
//
//                try {
//                    data.save(UPLOAD_PATH + Constant.HEALTH_IMG_URL + File.separator + photoName + ".jpg");
//                    i++;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }
    /**
     * @Description: 组装缺陷对象
     * @Param: List<String> rowValList word数据行
     * @Param: String id 主键
     * @Return: Flaw 对象
     * @Author: haoshuai
     * @Date: 2020/7/27
     */
    private FlawDO assemblyFlaw(List<String> rowValList, String id) {
        FlawDO flaw = new FlawDO();
        flaw.setId(GuidUtil.get());
        flaw.setHealthId(id);
        if (StringUtils.isEmpty(rowValList.get(0))) {
            flaw.setLocation(0.0);
        } else {
            flaw.setLocation(Double.valueOf(rowValList.get(0).replace("m", "")));
        }
        flaw.setDefectId(healthServiceImpl.getDefectId(rowValList.get(1)));
        if (StringUtils.isNotEmpty(flaw.getDefectId())) {
            flaw.setDefectLevelId(healthServiceImpl.getDefectLevelId(flaw.getDefectId(), rowValList.get(3)));
        }
        flaw.setPipelineSituation(rowValList.get(4));
        flaw.setPhotoName(rowValList.get(5));
        flaw.setDel(Constant.NOT_DEL);
        return flaw;
    }

    /**
     * @Description: 组装健康检测对象
     * @Param: List<String> rowValList word数据行
     * @Param: Health 对象
     * @Return: Health 对象
     * @Author: haoshuai
     * @Date: 2020/7/27
     */
    private HealthBO assemblyHealth(List<String> rowValList, HealthBO health) {
        for (int i = 0; i < rowValList.size(); i++) {
            switch (rowValList.get(i)) {
                case "录像文件":
                    health.setVideoName(rowValList.get(i + 1));
                    break;
                case "起始井号":
                    health.setStartPoint(rowValList.get(i + 1));
                    break;
                case "终止井号":
                    health.setEndPoint(rowValList.get(i + 1));
                    break;
                case "敷设年代":
                    try {
                        health.setConstructionDate(LocalDate.parse(rowValList.get(i + 1)));
                    } catch (Exception e) {
                        break;
                    }
                    break;
                case "起点埋深":
                    if (StringUtils.isNotEmpty(rowValList.get(i + 1))) {
                        health.setStartBury(Double.valueOf(rowValList.get(i + 1).replace("m","")));
                    }
                    break;
                case "终点埋深":
                    if (StringUtils.isNotEmpty(rowValList.get(i + 1))) {
                        health.setEndBury(Double.valueOf(rowValList.get(i + 1).replace("m","")));
                    }
                    break;
                case "管段类型":
                    health.setUses(rowValList.get(i + 1));
                    break;
                case "管段材质":
                    health.setMaterial(rowValList.get(i + 1));
                    break;
                case "管段直径":
                    String diameter = rowValList.get(i + 1);
                    health.setDiameter(diameter);
                    try {
                        if (StringUtils.isNotEmpty(diameter)) {
                            health.setPipeDiameter(Integer.valueOf(diameter.replace("m", "")));
                        }
                    } catch (Exception e) {
                        break;
                    }
                    break;
                case "检测方向":
                    health.setDirection(rowValList.get(i + 1));
                    break;
                case "管段长度":
                    String lengthLine = rowValList.get(i + 1);
                    try {
                        health.setLengthLine(StringUtils.isEmpty(lengthLine) ? null : Double.valueOf(lengthLine.replace("m", "")));
                    } catch (Exception e) {
                        break;
                    }
                    break;
                case "检测长度":
                    String detectionLine = rowValList.get(i + 1);
                    try {
                        health.setDetectionLine(StringUtils.isEmpty(detectionLine) ? null : Double.valueOf(detectionLine.replace("m", "")));
                    } catch (Exception e) {
                        break;
                    }
                    break;
                case "修复指数":
                    String repairIndex = rowValList.get(i + 1).replace("——", "").replace("\\", "").replace("/", "");
                    try {
                        health.setRepairIndex(Double.valueOf(repairIndex));
                    } catch (Exception e) {
                        break;
                    }
                    break;
                case "养护指数":
                    String maintenanceIndex = rowValList.get(i + 1).replace("——", "").replace("\\", "").replace("/", "");;
                    try {
                        health.setMaintenanceIndex(Double.valueOf(maintenanceIndex));
                    } catch (Exception e) {
                        break;
                    }
                    break;
                case "检测人员":
                    health.setMonitoringPersonnel(rowValList.get(i + 1));
                    break;
                case "检测日期":
                    try {
                        health.setMonitoringDate(LocalDate.parse(rowValList.get(i + 1)));
                    } catch (Exception e) {
                        break;
                    }
                    break;
                case "检测地点":
                    health.setMonitoringSite(rowValList.get(i + 1));
                    break;
                default:
                    break;
            }
        }

        return health;
    }

    private Boolean isNumber(String s) {
        return s.matches("-?[0-9]+(\\.[0-9]+)?");
    }

}
